﻿
namespace Numbrella.Tracker.Data
{
    using System.Collections.Generic;
    using Numbrella.Interaction;

    public partial class Problem
    {                
        public ProblemDefinition ToDefinition()
        {
            ProblemDescription description = new ProblemDescription(this.Description);
            ProblemImplementation implementation = new ProblemImplementation(this.GetTypeNames(), this.Assembly);
            ProblemCredentials credentials = new ProblemCredentials(new System.Uri(this.Uri));
            ProblemDefinition definition = new ProblemDefinition(this.Name, description, implementation, credentials);

            return definition;
        }

        private IEnumerable<string> GetTypeNames()
        {
            if (!this.AdditionalTypes.IsLoaded)
                this.AdditionalTypes.Load();

            List<string> typeNames = new List<string>();
            foreach (AdditionalType type in this.AdditionalTypes)
            {
                typeNames.Add(type.FullName);
            }

            return typeNames;
        }
    }
}